/**
 * Created by yangxianming on 2017/4/11.
 */
//全局变量
function initializeData(){
    var xmlHttp1 = new XMLHttpRequest();
    xmlHttp1.onreadystatechange = function(){
        if (xmlHttp1.readyState==4){
            if(xmlHttp1.status==200){
            }
        }
    };
    xmlHttp1.open("GET", "/welcome", true);
    xmlHttp1.send();
}

function myLogin(){
    var u = document.getElementsByTagName("input")[0].value;
    var p = document.getElementsByTagName("input")[1].value;
    var un = "username="+u;
    var pw = "password="+p;

    var xmlHttp1 = new XMLHttpRequest();
    xmlHttp1.onreadystatechange = function(){
        if (xmlHttp1.readyState==4){
            if(xmlHttp1.status==200){
                var r = JSON.parse(xmlHttp1.response);
                if (r["apiStatus"] == "0") {
                    var p = document.getElementById("errmsg");
                    p.innerText = r["errorMsg"];
                }
                if (r["apiStatus"] == "1"){
                    window.location.href = r["result"];
                }
            }
        }
    };
    xmlHttp1.open("GET", "/login?"+un+"&"+pw, true);
    xmlHttp1.send();
}
function guestLogin(){
    var un = "username=guest";
    var pw = "password=111111";

    var xmlHttp1 = new XMLHttpRequest();
    xmlHttp1.onreadystatechange = function(){
        if (xmlHttp1.readyState==4){
            if(xmlHttp1.status==200){
                var r = JSON.parse(xmlHttp1.response);
                if (r["apiStatus"] == "0") {
                    var p = document.getElementById("errmsg");
                    p.innerText = r["errorMsg"];
                }
                if (r["apiStatus"] == "1"){
                    window.location.href = r["result"];
                }
            }
        }
    };
    xmlHttp1.open("GET", "/login?"+un+"&"+pw, true);
    xmlHttp1.send();
}